<template>
  <div class="box">
    <p class="title">新增产品分类</p>
    <el-form :model="info" status-icon ref="form" label-width="110px" :rules="rules">
      <el-form-item label="模板id" prop="id">
        <el-input v-model="info.id"></el-input>
      </el-form-item>
      <el-form-item label="短信类型" prop="type">
        <el-select placeholder="请选择" v-model="info.type">
          <el-option label="普通短信" :value="0"></el-option>
          <el-option label="营销短信" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="地域类型" prop="international">
        <el-select placeholder="请选择" v-model="info.international">
          <el-option label="国内短信" :value="0"></el-option>
          <el-option label="海外短信" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="模板状态" prop="status">
        <el-select placeholder="请选择" v-model="info.status">
          <el-option label="已通过" :value="0"></el-option>
          <el-option label="待审核" :value="1"></el-option>
          <el-option label="已拒绝" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="模板内容" prop="text">
        <el-input type="textarea" v-model="info.text"></el-input>
      </el-form-item>
      <el-form-item label="审批信息" prop="reply">
        <el-input type="textarea" v-model="info.reply"></el-input>
      </el-form-item>

      <el-form-item class="all-handle-btn-box">
        <el-button type="primary" @click="handleCertain(info)">确定</el-button>
        <router-link class="back-btn" to="/sms/list"><el-button>返回</el-button></router-link>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      info: {},
      parentList: [],
      rules: {
        id: {required: true, message: '模板id不能为空', trigger: 'change'},
        type: {required: true, message: '短信类型不能为空', trigger: 'change'},
        international: {required: true, message: '地域类型不能为空', trigger: 'change'},
        status: {required: true, message: '模板状态不能为空', trigger: 'change'},
        text: {required: true, message: '模板内容不能为空', trigger: 'change'},
        reply: {required: true, message: '审批信息不能为空', trigger: 'change'}
      }
    }
  },
  methods: {
    handleCertain(info) {
      let _this = this;
      this.$refs.form.validate(bool => {
        if (bool) {
          this.$confirm("确定要保存么?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(() => {
            //修改提交
            this.$ajax({
              url:'productclass/addClass',
              data: {
                app:{
                  parentID: info.parentID,
                  className: info.className,
                  status: info.status
                }
              },
              success(res) {
                if (res.data.code === 1) {
                  _this.$message({
                    message: res.data.msg,
                    type: 'success',
                    onClose(){
                      _this.$router.push( {name:'typeList'} );
                    }
                  });
                } else {
                  _this.$message({
                    message: res.data.msg,
                    type: 'warning'
                  });
                }
              }
            });
          }).catch(() => {});
        }
      });
    }
  }
};
</script>

<style scoped>
.el-form {
  width: 50%;
  margin: 0 auto;
}
.title {
  margin-bottom: 20px;
  font-size: 20px;
  text-align: center;
}
.back-btn {
  margin-left: 10px;
}
</style>
